package Formatter;

import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import java.io.*;
 
public class Formatter {
    
    public Formatter() {
    }
    
    public static String format( String filePath, String xslPath )
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        System.out.println( Modelo.Util.readTextFile( xslPath ) + "\n" + Modelo.Util.readTextFile( filePath )  );
        
        try
        {
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer(new StreamSource(xslPath ));
            transformer.transform( new StreamSource(filePath ), new StreamResult( baos ));
        }
        catch( Exception ex )
        {
            System.err.println( "error convirtiendo a html " + ex.toString() );
            return "";
        }
         
        return baos.toString();
    }
}
